package com.ruoyi.common.utils;

import java.util.Random;

public class UIDUtil {
    private static  final int SHORT_MAX=5536;
    private static int counter=-1;

    public static synchronized long nextId() {
        long now = System.currentTimeMillis();
        if (counter == -1) {
            long seed = now ^ Thread.currentThread().getId();
            Random rnd = new Random(Long.hashCode(seed));
            counter = rnd.nextInt(SHORT_MAX);
        }
        Long id = (now << 16) | counter;
        counter = (counter + 1) % SHORT_MAX;
        String idt= id.toString().substring(3);
        return Long.valueOf(idt);
    }

    public static void main(String[] args) {
        for (int i=1; i<10; i++){

            System.out.println(nextId());
        }
    }
}
